
log using "log.log", replace

*     ***************************************************************** *
*     ***************************************************************** *
*     File-Name:  do.do                                                 *
*     Date:       September 2019                                        *
*     Author:     Eddie Hearn                                           *
*     Purpose:    Buying Globalization                                  *
*     Input File: DATA.dta                                              *
*     Output File: log.log                                              *
*     Data Output: None                                                 *
*     Program:	  Stata 14
*     Machine:    Home                                                  *
*     ****************************************************************  *
*     ****************************************************************  *


use DATA.dta 



*     ****************************************************************  *
*          Generate Variables                                           *
*     ****************************************************************  *

gen TRADE = 1 if Q13B ==1
replace TRADE = 2 if Q13B ==3
replace TRADE = 3 if Q13B ==2
gen AGE = QF1 if QF1<9
gen GRAD = 0 if QF2 <7
replace GRAD = 1 if QF2 ==5|QF2 ==6
gen income = QF8 if QF8 < 8
sum income, detail
gen LOW = 1 if income<4
replace LOW = 0 if income>3
replace LOW = . if income ==.
drop income
gen UNEMP = 0 if Q8 <7
replace UNEMP =1 if Q8 ==3
gen POLIT = 1 if QF7 ==1
replace POLIT = 2 if QF7 ==3
replace POLIT = 3 if QF7 ==2
gen FEMALE  = qa -1
gen SOCIO = 1 if Q4A1==1| Q4A1==3
replace SOCIO = 1 if Q4A2==1| Q4A2==3
recode SOCIO (.=0)
gen CHILD = Q16C if Q16C<5
gen ENVIRO = Q16D if Q16D<5
gen UNION = Q16F if Q16F<5
gen POST = ((CHILD + ENVIRO + UNION)*-1) +13
drop CHILD ENVIRO UNION
gen JPN = 1 if Q21A==2
replace JPN = 2 if Q21A==3
replace JPN = 3 if Q21A==1

gen ROK = 1 if Q21B==2
replace ROK = 2 if Q21B==3
replace ROK = 3 if Q21B==1


gen WE = 1 if Q21C==2
replace WE = 2 if Q21C==3
replace WE = 3 if Q21C==1

gen EE = 1 if Q21D==2
replace EE = 2 if Q21D==3
replace EE = 3 if Q21D==1

gen AF = 1 if Q21E==2
replace AF= 2 if Q21E==3
replace AF = 3 if Q21E==1

gen IN = 1 if Q21F==2
replace IN= 2 if Q21F==3
replace IN = 3 if Q21F==1

gen CHU = 1 if Q21G==2
replace CHU= 2 if Q21G==3
replace CHU = 3 if Q21G==1

gen MEX = 1 if Q21H==2
replace MEX= 2 if Q21H==3
replace MEX = 3 if Q21H==1

gen CAN = 1 if Q21I==2
replace CAN= 2 if Q21I==3
replace CAN = 3 if Q21I==1

gen CATEGORY = (JPN + ROK + WE + EE + AF + IN + CHU + MEX + CAN) - 8 
gen CON_OR = (JPN + ROK + WE + EE + AF + IN + CHU + MEX + CAN) - 18 
gen REDUCED = (JPN + ROK + WE + EE + AF + IN  + MEX + CAN)- 16 

drop JPN ROK  WE  EE  AF  IN CHU  MEX  CAN


*     ****************************************************************  *
*          Models 1-3  MNM LOGIT                                        *
*     ****************************************************************  *

mlogit TRADE CON_OR, robust base(2)
mlogit TRADE CON_OR GRAD  LOW UNEMP FEMALE  AGE POLIT, robust base(2)
mlogit TRADE CON_OR GRAD  LOW UNEMP FEMALE  AGE POLIT SOCIO POST, robust base(2)
estimates store IV_ORDINAL

*     ****************************************************************  *
*          Models 1-3  ORDINAL LOGIT                                    *
*     ****************************************************************  *

ologit TRADE CON_OR, robust
ologit TRADE CON_OR GRAD  LOW UNEMP FEMALE  AGE POLIT, robust 
ologit TRADE CON_OR GRAD  LOW UNEMP FEMALE  AGE POLIT SOCIO POST, robust


*     ****************************************************************  *
*          Models 1-3  Reduced Measure - Excluding CHINA                *
*     ****************************************************************  *

mlogit TRADE REDUCED, robust base(2)
mlogit TRADE REDUCED GRAD  LOW UNEMP FEMALE  AGE POLIT, robust base(2)
mlogit TRADE REDUCED GRAD  LOW UNEMP FEMALE  AGE POLIT SOCIO POST, robust base(2)


*     ****************************************************************  *
*           Consumer Orientation (Ordinal vs Categorical)               *
*     ****************************************************************  *

mlogit TRADE i.CATEGORY GRAD  LOW UNEMP FEMALE  AGE POLIT SOCIO POST, robust base(2)
estimates store IV_CATEGORICAL
estimates stats IV_ORDINAL IV_CATEGORICAL

*     ****************************************************************  *
*            Hausman-McFadden Test                                      *
*     ****************************************************************  *

mlogit TRADE CON_OR GRAD  LOW UNEMP FEMALE  AGE POLIT SOCIO POST
estimates store FULL

mlogit TRADE CON_OR GRAD  LOW UNEMP FEMALE  AGE POLIT SOCIO POST if TRADE!=2
estimates store NUETRAL_ELIMINATED

mlogit TRADE CON_OR GRAD  LOW UNEMP FEMALE  AGE POLIT SOCIO POST if TRADE!=1
estimates store BEN_ELIMINATED

hausman FULL  NUETRAL_ELIMINATED, alleqs constant
hausman FULL  BEN_ELIMINATED, alleqs constant


*     ****************************************************************  *
*       Install  Clarify                                                *
*     ****************************************************************  *


**** net from https://gking.harvard.edu/clarify/  ****
**** net get clarify                              ****                          

*     ****************************************************************  *
*       Predicted Prob w/ Clarify                                       *
*     ****************************************************************  *
	
estsimp mlogit TRADE CON_OR GRAD  LOW UNEMP FEMALE  AGE POLIT SOCIO POST, robust base(2)
setx median
sum CON_OR, detail
setx CON_OR -3
simqi,  genpr(pro25 nut25 con25)
setx CON_OR 0
simqi,  genpr(pro75 nut75 con75)

gen pro_diff = pro25 - pro75
gen nut_diff = nut25 - nut75
gen con_diff = con25 - con75

centile pro25 nut25 con25 pro75 nut75 con75, centile (50) 
centile pro_diff nut_diff con_diff, centile (2.5 50 97.5) 

